Subject: LW to VLab Motion ARexx script
From: [email-masked]
To: [email-masked]
Date: Fri, 17 Feb 1995 21:48:46 -0500 (EST)

OK, by popular demand, here is my ARexx script that will automatically
import LW frames into VLab Motion and then delete them. 'Course you could
adapt it to other uses. In fact, I adapted it from another one I wrote
that moved files over AmigaLink (floppy port) network--much faster
than having LW write the files to the network.

Hope someone finds this useful.  As noted in the script header, it
is very important to increase the task priority for VLab Motion.

--Doug

/*
** LW2VLM.rexx
**
** $VER: LW2VLM.rexx 1.0.0 (02.13.95)
**
**
** Waits for LightWave 3D frames to be rendered and then imports them
** to a user-defined VLab-Motion MovieShop scene.
**
** !!!YOU MUST HAVE A PROJECT OPEN!!!
**
** Very rough but useful information about frame rendering time will
** be displayed.
**
** If importing a file fails, the script will sense this and retry an
** unlimited amount of times, so don't worry.  This is indicated by
** the Import 'Attempt' information.
**
** See bottom of this script for syntax.  Running script with no
** additional information will show syntax.  (e.g., RX LW2VLM)
**
** Creates small log file in RAM: called LW2VLM.log
**
** To get this to work properly, you must run MovieShop at a higher
** task priority than LightWave. The easiest way is to run MovieShop
** from the CLI using the following steps:
**
**    1) Open a CLI window.
**    2) Type: "ChangeTaskPri 5" and press Return. (Don't enter 
**       quotes.)
**    3) CD to your MovieShop directory.
**    4) Type: "Run MovieShop" and press Return. (no quotes)
**    5) Open an existing or start a new MovieShop project.
**    6) Now run this script will the appropriate arguments.
**
** There are also utilities available that allow you to change a task
** priority while things are running. If you don't adjust the MovieShop
** task priority higher than LightWave, the LightWave rendering process
** will hog the CPU and the files will not be imported on a timely
** basis.
**
** Copyright © 1995 Douglas J. Nakakihara
** All rights reserved
**
** Contact author at [email-masked]
**
** This script is freely distributable.
*/

Parse arg Basename Scenename Total First Increment
options failat 21
options results
signal on Break_C

/*
** Log filename
*/

LogFN = 'ram:LW2VLM.log'

/*
** LightWave numeric extension length. If the extension length is
** ever changed, you only need to change this variable. NOTE: if
** frame numbering exceeds 999 or 9999, script will automatically
** increment this to 4 and 5, respectively.
*/

Extension = 3

/*
** Checks for essential arguments
*/
 
If Basename = '' then do
  Call Syntax
  Exit
End

If Scenename = '' then do
  Call Syntax
  Exit
End

If Total = '' then do
  Call Syntax
  Exit
End
Total = strip(Total)

/*
** Sets import parameters. Note if you will be importing fields,
** you will have to change the ImportPicType to 'Field' from 
** 'Frame'. Also, the size correction has been set to scale. For
** best results, render to the exact size used for your project
** using LightWave's custom size feature.
*/

Address MOVIESHOP

ImportMethod Multipic
ImportPicType Frames
CorrectImportHeight Scale
CorrectImportWidth Scale

/*
** If Scenename already exists, it is made the current scene and
** the dummy frame is made the current frame.
*/

NewScene Scenename
If rc ~= 0 then do
  Say 'Scenename already exists. Appending to it.'
  GoToScene Scenename
End

Address ()

/*
** library necessary for Delay command
*/

Lib='rexxsupport.library'
if ~show('L',Lib) then call addlib(Lib,0,-30,0)

/*
** Extract basename without path
*/

Basename2 = Basename
A = lastpos("\", Basename2)
If A > 0 then do
  Basename2 = substr(Basename2, A + 1)
End
A = lastpos(":", Basename2)
If A > 0 then do
  Basename2 = substr(Basename2, A + 1)
End

/*
** Set Increment to 1 if not given
*/

If Increment = '' then do
  Increment = 1
End
Increment = strip(Increment)

/*
** Set First to 1 if not given
*/

If First = '' then do
  First = 1
End
First = strip(First)

/*
** Write header to log file. Append if file exists
*/

Call OpenLog
Writeln('logfile', '>>>> LW2VLM '||Basename||' '||Scenename,
       ||' '||Total||' '||First||' '||Increment||' <<<<')
Close('logfile')

/*
** Initialize counter 
*/

Counter = First
Do while Counter <= Total

  /*
  ** Initialize various things
  */
  
  Call time('R')
  Counter = strip(Counter)
  If Counter > 999 then Extension = 4
  If Counter > 9999 then Extension = 5
  Filename = Basename || right(Counter,Extension,'0')
  Filename2 = Basename2 || right(Counter,Extension,'0')
  RC=99
  Imports = 0

  Say 'Waiting for ' || Filename || '... (Ctrl-C to abort)'
  
  Do while (RC ~= 0)

    /*
    ** Wait for file
    */
    
    Do while ~open('Testing', Filename, 'R')
      Call delay(230)
    End
    Call delay(45)
    Close('Testing')
    Call delay(200)

    /*
    ** Copy to VLM partition
    */
    
    Imports = Imports + 1
    Say ' -Importing (Attempt: ' || Imports || ') to ' || Scenename
    
    /*
    ** Before importing, the script goes to the last frame in the
    ** scene and then one more over to the dummy frame. This makes
    ** it so the image is always added to the end of the scene.
    */

    Address MOVIESHOP
    GoToFrame Last
	GoToFrame Next
    Importframe Filename
    Address ()

  End

  Say ' -Deleting source file'
  Address command 'delete >nil: ' || Filename

  /*
  ** Calculate timing information
  */
  
  TESec = trunc(time('E')) /* Total Elapsed Seconds */
  FPH = trunc(3600/TESec, 2) /* Frames Per Hour */
  EMin = trunc(TESec/60)
  ESec = trunc(TESec - (EMin * 60))
  RendTime = EMin||'m ' || ESec || 's'
  Say ' -Frame render time: ' || RendTime || ' (Frames/hour: '||FPH||')'

  FRemain = trunc((Total - Counter) / Increment)
  Say ' -Frames remaining: ' || FRemain

  ERS = trunc(FRemain * TESec) /* Est. Remaining Seconds */
  ERHrs = trunc(ERS/3600)
  ERMin = trunc((ERS/60) - (ERHrs * 60))
  ERSec = ERS - (trunc(ERS/60) * 60)
  Say ' -Estimated remaining time: '||ERHrs||'h '||ERMin||'m '||ERSec||'s'

  /*
  ** Update log file 
  */
  
  Call OpenLog
  Message = Filename2||': Import attempts: '||Imports||' Render time: ',
            ||RendTime
  Writeln('logfile', Message)
  Close('logfile')

  /*
  ** Increment frame counter
  */
  
  Counter = Counter + Increment

End

Say 'All done!'

Call OpenLog
Writeln('logfile', 'All done!')
Close('logfile')
Exit

Syntax:

  Say 'Syntax : LW2VLM <Basename> <Scenename> <Last> <First> <Incr>'
  Say ''
  Say 'Purpose: Imports rendered files to Scenename as they are rendered.'
  Say ''
  Say '  Basename  = Filename to look for, excluding numeric'
  Say '              extension. Include period, if used (e.g., PIC.)'
  Say '              Basename can include path, like RAM:PIC.'
  Say '  Scenename = MovieShop scene name. Appends if it already exists.'
  Say '  Last      = Last frame being rendered'
  Say '  First     = Actual number of first frame'
  Say '  Incr      = Frame number increment'
  Say ''
  Say '  * If First or Incr is omitted, then 1 is used.'
  Say '  * Use Control-C to abort.'
  Say '  * Example: RX LW2VLM ram:pic. MyScene 70 31 2'
  Say '    The LightWave scene has 70 frames, the first frame to'
  Say '    be rendered is PIC.31, and frames will be incremented'
  Say '    by 2. The frames will be imported into scene named MyScene'
  Return

OpenLog:

  If ~Open('logfile', LogFN, 'A') then do
    If ~Open('logfile', LogFN, 'W') then do
      Say 'Error opening log file!'
      Exit
    End
  End
  Return

Break_C:

  Say 'Control-C detected...'
  Say 'Line' SIGL 'RC='RC
  Exit

/*

History:

1.0.0 First version

*/